<?php

/***  DOCUMENTATION LAYER

Ceo Module Template

Last Update: Sep 2007
  
DESCRIPTION
  this file provides a template for other simple unit tests
  
NOTES
  This is a very loose template for a module.  There is almost limitless 
  flexibility with modules.  Just remember that they are called by a method
  of the $Ceo framework class, thus they have access to framework properties
  and methods, though the $this var, but otherwise have local scope of the
  method.
  
  A module should also package three return values in the array $_MOD['Return']:
  
    $_MOD['Return'][0] : string - for display in browser    
    $_MOD['Return'][1] : boolean (0/1) - successful/without exception?
    $_MOD['Return'][2] : assoc. array - data (as a side-effect)
    
    
  This template is also a working example, as it is called by the unit.module.php
  file (simply point your browser at that file to test):
      
______________________________________________________________________________*/

// *** Initialize / Unpackage Arguments

// Return Values
$_MOD['Return'][0] = '';        // string
$_MOD['Return'][1] = 0;         // success
$_MOD['Return'][2] = array();   // data

// Triggers
$_TRIGGER['event'] = 0;

// Show Triggers
$_SHOW['output'] = 0;
  


// *** Controller

// default
$_TRIGGER['event'] = 1;


// *** Events

// demo event (exposes module structure)
if ( $_TRIGGER['event'] )
{
  // set MOD Return data values
  $_MOD['Return'][2] = array( 'DATA' => array('data', 'as', 'a side effect') );

  $_HTML['arg'] = '';
  foreach ( $_MOD['ARG'] as $_arg )
  {
    $_HTML['arg'] .= "<p>$_arg</p>";
  }
  
  $_HTML['calling_file'] = highlight_file('unit.module.php', 1);
  $_HTML['mod_file'] = highlight_file(__FILE__, 1);
  $_HTML['mod_content'] = print_r($_MOD, 1);
  
  $_SHOW['output'] = 1;
}



// *** Output

if ( $_SHOW['output'] )
{
  $_MOD['Return'][1] = 1;

  $this_file = __FILE__;
  $_MOD['Return'][0] = <<<HTML
  
<h2 style="margin:8px 0 0;">Module Return String</h2>

<h4 style="margin:8px 0 0;">\$_MOD[ARG] (processed)</h4>
<pre style="background-color:#ccc;">{$_HTML['arg']}</pre>

<h4 style="margin:8px 0 0;">calling file: unit.module.php</h4>
<pre style="background-color:#ccf;">{$_HTML['calling_file']}</pre>

<h4 style="margin:8px 0 0;">this file: $this_file</h4>
<pre style="background-color:#cfc;">{$_HTML['mod_file']}</pre>

<h4 style="margin:8px 0 0;">\$_MOD array</h4>
<pre style="background-color:#fcc;">
{$_HTML['mod_content']}
\$_MOD['Return'][1] now: {$_MOD['Return'][1]}
\$_MOD['Return'][0] now: you're looking at it
</pre>
  
HTML;

}

// *** Return

return $_MOD['Return'];

/*
  It's that simple.  This array is returned by the load_mod method to the 
  controller, which can do with it as it wishes.  Usually, $_MOD['Return'][0]
  will be handed off to an $_HTML value for display in the Output section.)  
*/

?>
